﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using VietImage.Models;

namespace VietImage.Supports
{
    public class LogDateComparer : IComparer<System.Object>
    {
        public int Compare(System.Object x, System.Object y)
        {
            if (GetDate(x) > GetDate(y))
                return 1;
            if (GetDate(x) == GetDate(y))
                return 0;
            return -1;
        }

        public DateTime GetDate(System.Object ob)
        {
            switch (ob.GetType().ToString())
            {
                case "VietImage.Models.LogCategory":
                    {
                        LogCategory log = (LogCategory)ob;
                        return log.ActionTime;
                    }
                case "VietImage.Models.LogCustomer":
                    {
                        LogCustomer log = (LogCustomer)ob;
                        return log.ActionTime;
                    }

                case "VietImage.Models.LogEmail":
                    {
                        LogEmail log = (LogEmail)ob;
                        return log.ActionTime;
                    }

                case "VietImage.Models.LogImage":
                    {
                        LogImage log = (LogImage)ob;
                        return log.ActionTime;
                    }

                case "VietImage.Models.LogImageCategory":
                    {
                        LogImageCategory log = (LogImageCategory)ob;
                        return log.ActionTime;
                    }

                case "VietImage.Models.LogImageLightbox":
                    {
                        LogImageLightbox log = (LogImageLightbox)ob;
                        return log.ActionTime;
                    }

                case "VietImage.Models.LogLightbox":
                    {
                        LogLightbox log = (LogLightbox)ob;
                        return log.ActionTime;
                    }

                case "VietImage.Models.LogNoticeEmail":
                    {
                        LogNoticeEmail log = (LogNoticeEmail)ob;
                        return log.ActionTime;
                    }

                case "VietImage.Models.LogPayment":
                    {
                        LogPayment log = (LogPayment)ob;
                        return log.ActionTime;
                    }

                case "VietImage.Models.LogRecentActivity":
                    {
                        LogRecentActivity log = (LogRecentActivity)ob;
                        return log.ActionTime;
                    }

                case "VietImage.Models.LogSubscriber":
                    {
                        LogSubscriber log = (LogSubscriber)ob;
                        return log.ActionTime;
                    }

                case "VietImage.Models.LogTranslation":
                    {
                        LogTranslation log = (LogTranslation)ob;
                        return log.ActionTime;
                    }

                case "VietImage.Models.LogUser":
                    {
                        LogUser log = (LogUser)ob;
                        return log.ActionTime;
                    }
            }
            return DateTime.Now;
        }
    }
}